import Split from 'split.js'
/**
 * 
 * @param contanierClass1 容器名字
 * @param minSize1 左边容器最小宽度
 * @param contanierClass2 容器名字
 * @param minSize2 右边容器最小宽度
 */
export function splitInit(contanierClass1:string, contanierClass2:string, minSize1:number, minSize2:number,) {
    let sizes:any = localStorage.getItem('split-sizes')
    let sizeCodes:any = localStorage.getItem('split-sizes-code')

    if (sizes) {
        sizes = JSON.parse(sizes)
    } else {
        sizes = [50, 50] // default sizes
    }

    if (sizeCodes) {
        sizeCodes = JSON.parse(sizeCodes)
    } else {
        sizeCodes = [70, 30] // default sizes
    }

    Split([contanierClass1,  contanierClass2], {
        sizes: sizes,
        gutterSize: 1,
        minSize: [minSize1, minSize2],
        gutter: (index, direction) => {
            const gutter = document.createElement('div')
            gutter.className = `gutter gutter-${direction}` ;
						
            const icon = `<div class='narrow'>
            <span class='iconfont icon-left'></span>
            <span class='iconfont icon-right'></span>
            </div>`
            gutter.innerHTML=icon;
            gutter.addEventListener("mousemove", () => {
                gutter.style.cursor = 'col-resize';
				        
            })
            return gutter
        }, 
		onDragEnd: function (sizes) {
            localStorage.setItem('split-sizes', JSON.stringify(sizes))
        },
    })
}